package com.qiaofang.applet.common.util;

import java.security.SecureRandom;
import java.util.Random;

/**
 * 验证码工具类
 * @author QF2019
 */
public class CaptchaUtil {

    /**
     * 验证码源数据
     */
    private static final String SYMBOLS = "0123456789";

    private static final Random RANDOM = new SecureRandom();

    /**
     * 获取长度为 指定位数的 的随机数字
     * @return num
     */
    public static String generateCaptcha(int num) {
        char[] nonceChars = new char[num];

        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars);
    }
}
